<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    function countDown(time){
        var nowTime= new Date();
        var inputTime = +new Date(time);//获取用户输入的总毫秒数
        var times = (inputTime - nowTime)/1000;
        var d = parseInt(times/60/60/24);
        if (d<10){
            d = '0'+d;
        }
        var h = parseInt(times/60/60%24 );        
        if (h<10){
            h = '0'+h;
        }
        var m =  parseInt(times/60%60);
        if (m<10){
            m = '0'+m;
        }
        var s = parseInt(times % 60);
        if(s<10){
            s = '0' + s;
        }
        return '倒计时为:'+ d + '天' + h + '小时' + m + '分' + s + '秒';
    }console.log(countDown('2020-9-22 21:00:00'));
    
    var nowTime1 = new Date();
    var time = prompt('输入时间');
    var inputTime1 = +new Date(time);
    var times1 = (inputTime1-nowTime1)/1000;
    var d1=parseInt(times1/60/60/24);
    if(d1<10){
        d1 = '0'+ d1;
    }
    var h1 = parseInt(times1/60/60%24);
    if(h1<10){
        h1 = '0'+h1;
    }
    var m1 = parseInt(times1/60%60);
    if(m1<10){
        m1 ='0' + m1;
    }
    var s1  = parseInt(times1%60);
    if(s1<10){
        s1 = '0' + s1;
    }
    console.log('倒计时为:'+ d1 + '天' + h1 + '小时' + m1 + '分' + s1 + '秒');


</script>
<body>
    
</body>
</html>